#include<iostream>
#include<string>
using namespace std;
string longestPalindrome(string s)
{
    int size = s.size(), begin = 0, len = 0;
    for (int cur = 0; cur < size; cur++)
    {
        int left = cur - 1, right = cur + 1;
        for (; left >= 0 && right < size; left++, right--)
        {
            if (s[left] != s[right]) break;
        }
        int x = right - left - 1;
        if ( x> len)
        {
            begin = left + 1;
            len = right - left - 1;
        }
        left = cur, right = cur + 1;
        for (; left >= 0 && right < size; left++, right--)
        {
            if (s[left] != s[right]) break;
        }
        x = right - left - 1;
        if (x > len)
        {
            begin = left + 1;
            len = right - left - 1;
        }
    }
    return s.substr(begin, len);
}
int main()
{
    string nnn= longestPalindrome("babad");
    cout << nnn << endl;
    return 0;
}
